package com.example.a22310.myapplication.Beans;

import android.content.Intent;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.BindingAdapter;
import android.view.View;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.io.Serializable;
import java.util.List;

import static com.example.a22310.myapplication.GloableClass.Yuejian.IMG_URL;

public class Post {

    private int code;
    public static boolean LOVENUMBER = false;
    private List<PostlistBean> postlist;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public List<PostlistBean> getPostlist() {
        return postlist;
    }

    public void setPostlist(List<PostlistBean> postlist) {
        this.postlist = postlist;
    }

    public static class PostlistBean extends BaseObservable implements Serializable {
        /**
         * postid : 1
         * userid : 2
         * username : 小牛
         * photo : 1.png
         * content : hello world，撒点吧开始的把控本事打卡上班打卡失败的
         * date : 2017-09-15
         * love_number : 1
         */

        private int postid;
        private int userid;
        private String username;
        private String photo;
        private String pic;
        private String content;
        private String date;
        private String love_number;



        public PostlistBean() {
        }

        public PostlistBean(int postid,int userid, String username, String photo,String pic, String content,String date,
                            String love_number) {
            this.postid = postid;
            this.userid = userid;
            this.username=username;
            this.photo =photo;
            this.pic =pic;
            this.content = content;
            this.date = date;
            this.love_number=love_number;
        }
        @BindingAdapter("photo")
        public static void loadInternetImage(ImageView iv, String photo) {
            photo = IMG_URL+photo;
            Picasso.with(iv.getContext()).load(photo).into(iv);
        }


        @Override
        public String toString() {
            return "PostlistBean{" +
                    "postid='" + postid + '\'' +
                    ", userid='" + userid + '\'' +
                    ", username='" + username + '\'' +
                    "photo='" + photo + '\'' +
                    "pic='" + pic + '\'' +
                    ", content='" + content + '\'' +
                    ", date='" + date + '\'' +
                    "love_number='" + love_number + '\'' +
                    '}';
        }

        public void onItemClick(View view){
            Intent intent=new Intent(view.getContext(),PostDetail.class);
            //往详情传递数据
            PostlistBean postlistBean = new PostlistBean();
            postlistBean.setUserid(getUserid());
            postlistBean.setPostid(getPostid());
            postlistBean.setUsername(getUsername());
            postlistBean.setDate(getDate());
            postlistBean.setContent(getContent());
            postlistBean.setPhoto(getPhoto());
            postlistBean.setPic(getPic());
            postlistBean.setLove_number(getLove_number());
            intent.putExtra("post",postlistBean);
            view.getContext().startActivity(intent);
        }

        @Bindable


        public int getPostid() {
            return postid;
        }

        public void setPostid(int postid) {
            this.postid = postid;
        }

        public int getUserid() {
            return userid;
        }

        public void setUserid(int userid) {
            this.userid = userid;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPhoto() {
            return IMG_URL+photo;
        }

        public void setPhoto(String photo) {
            this.photo = photo;
        }

        public String getPic() {
            return IMG_URL+pic;
        }

        public void setPic(String pic) {
            this.pic = pic;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getDate() {
            return date;
        }

        public void setDate(String date) {
            this.date = date;
        }

        public String getLove_number() {
            return love_number;
        }

        public void setLove_number(String love_number) {
            this.love_number = love_number;
        }
    }

}
